<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/static/commons/taglibs.jsp"%>
<%@ include file="/static/commons/meta.jsp"%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>${title }</title>
<!--自定义index样式-->
<link rel="stylesheet" href="${ctx }/static/styles/basic/basic.css"></link>
<link rel="stylesheet" href="${ctx }/static/styles/edit/tableStyle.css"></link>
<!--js库-->
<%@ include file="/static/commons/jquery-easyui.jsp"%>
<script type="text/javascript" src="${ctx}/static/scripts/set_select.js"></script>
<script type="text/javascript">
	var headers = {};
	headers['__RequestVerificationToken'] = "${RequestVerificationToken}";
</script>
<style type="text/css">
body{overflow: hidden; padding: 10px 20px;}
.table-utd tbody td:first-child {width: 20px; text-align: center;}
.table-utd tbody td:not(:first-child){min-width:90px; }
.table-utd tbody td:last-child {width: 40px; min-width:40px; text-align: center;}
.choose_icon{background: url(${ctx}/static/images/common/choose.png) no-repeat; width: 24px; height: 24px; cursor: pointer;}
</style>
</head>

<body>
	<c:set var="disabled" value=""></c:set>
	<c:set var="ifSelect" value=""></c:set>
	<c:set var="isHide" value=""></c:set>
	<c:if test="${not empty view}">
		<c:set var="disabled" value="disabled"></c:set>
		<c:set var="ifSelect" value="false"></c:set>
		<c:set var="isHide" value="hidden"></c:set>
	</c:if>
	<table class="table-ltr">
		<caption>
			仪器配件确认单
			<label> 序号： ${obj.order_no}</label>
			<label> 编号： ${obj.order_id}</label>
		</caption>
		<tbody>
			<tr>
				<td>用户单位：</td>
				<td>
				<vvise:select id="custId" name="p_custId" sqlname="getCust" ifSelect="false" defval="${obj.cust_id}" />
				</td>
				<td>队号：</td>
				<td><input type="text" value="${obj.team_no }" disabled="disabled"></input></td>
					
				<td>接收日期：</td>
				<td><input type="text" value="<fmt:formatDate value="${obj.receive_date }" pattern="yyyy-MM-dd"/>" disabled="disabled" ></input>
				</td>
			</tr>
			<tr>
				<td>接单人：</td>
				<td>
					${obj.opt_user_ }
				</td>
				
				<td>业务员：</td>
				<td>
					<vvise:select id="serviceUser" name="p_serviceUser" sqlname="getServiceUser" 
								sqlparam="000105" ifSelect="false" defval="${obj.service_user}" className="full_select" />
				</td>
				<td colspan="2" class="td-empty">&nbsp;</td>
			</tr>
		</tbody>
	</table>
	
	<form id="editForm" action="${ctx}/partsConfirm/save" method="post">
		<input type="hidden" name="orderId" value="${obj.order_id }" />
		<div class="tab">
			<div class="tab-header">
				<ul>
					<li class="s0">气瓶</li>
					<li>气检仪</li>
					<li>空呼</li>
				</ul>
			</div>
			<div class="tab-body">
				<!-- 气瓶 -->
				<div class="tab-content s0">
					<table class="table-utd" id="qp">
						<thead>
							<tr>
								<th>&nbsp;</th>
								<th>名称</th>
								<th>生产厂家</th>
								<th>出厂编号</th>
								<th>容积</th>
								<th>出厂日期</th>
								<th>问题描述</th>
								<th>故障现象</th>
								<th>更换配件</th>
								<th>检测员</th>
								<th class="non-empty">配件确认</th>
								<th class="${isHide }">操作</th>
							</tr>
						</thead>
						<tbody>
							<c:set var="c1" value="0"></c:set>
							<c:forEach items="${details }" var="li" varStatus="i">
								<c:if test="${li.device_type eq 1 }">
								<tr>
									<c:set var="c1" value="${c1 + 1 }"></c:set>
									<td>${c1}<input type="hidden" name="logId" value="${li.log_id }"></input></td>
									<td>${li.device_name }</td>
									<td>${li.device_manufactor }</td>
									<td>${li.device_no }</td>
									<td>${li.volume_category_ }</td>
									<td>${li.manufacture_date }</td>
									<td>${li.issue_desc }</td>
									<td>${li.fault_name }</td>
									<td class="parts">${li.parts_name }</td>
									<td>${li.opt_user_ }</td>
									<td><vvise:select id="confirmStatus" name="confirmStatus" sqlname="getCodeData" defval="${li.confirm_status }"
										sqlparam="yes_or_no" className="full_select" ifSelect="${ifSelect }"/></td>
									<td class="${isHide }"><div class="choose_icon" title="更换配件"></div></td>
								</tr>
								</c:if>
							</c:forEach>
						</tbody>
					</table>
				</div>

				<!-- 气检仪 -->
				<div class="tab-content">
					<table class="table-utd" id="qjy">
						<thead>
							<tr>
								<th>&nbsp;</th>
								<th>名称</th>
								<th>生产厂家</th>
								<th>型号</th>
								<th>出厂编号</th>
								<th>气体种类</th>
								<th>问题描述</th>
								<th>故障现象</th>
								<th>更换配件</th>
								<th>检测员</th>
								<th class="non-empty">配件确认</th>
								<th class="${isHide }">操作</th>
							</tr>
						</thead>
						<tbody>
							<c:set var="c3" value="0"></c:set>
							<c:forEach items="${details }" var="li" varStatus="i">
								<c:if test="${li.device_type eq 3 }">
								<tr>
									<c:set var="c3" value="${c3 + 1 }"></c:set>
									<td>${c3}<input type="hidden" name="logId" value="${li.log_id }"></input></td>
									<td>${li.device_name }</td>
									<td>${li.device_manufactor }</td>
									<td>${li.device_model }</td>
									<td>${li.device_no }</td>
									<td>${empty li.gas_type ? "/" : li.gas_type_}</td>
									<td>${li.issue_desc }</td>
									<td>${li.fault_name }</td>
									<td class="parts">${li.parts_name }</td>
									<td>${li.opt_user_ }</td>
									<td><vvise:select id="confirmStatus" name="confirmStatus" sqlname="getCodeData" defval="${li.confirm_status }"
										sqlparam="yes_or_no" className="full_select" ifSelect="${ifSelect }"/></td>
									<td class="${isHide }"><div class="choose_icon" title="更换配件"></div></td>
								</tr>
								</c:if>
							</c:forEach>
						</tbody>
					</table>
				</div>

				<!-- 空呼 -->
				<div class="tab-content">
					<table class="table-utd" id="kh">
						<thead>
							<tr>
								<th>&nbsp;</th>
								<th>名称</th>
								<th>生产厂家</th>
								<th>型号</th>
								<th>出厂编号</th>
								<th>问题描述</th>
								<th>故障现象</th>
								<th>更换配件</th>
								<th>检测员</th>
								<th class="non-empty">配件确认</th>
								<th class="${isHide }">操作</th>
							</tr>
						</thead>
						<tbody>
							<c:set var="c2" value="0"></c:set>
							<c:forEach items="${details }" var="li" varStatus="i">
								<c:if test="${li.device_type eq 2 }">
								<tr>
									<c:set var="c2" value="${c2 + 1 }"></c:set>
									<td>${c2}<input type="hidden" name="logId" value="${li.log_id }"></input></td>
									<td>${li.device_name }</td>
									<td>${li.device_manufactor }</td>
									<td>${li.device_model }</td>
									<td>${li.device_no }</td>
									<td>${li.issue_desc }</td>
									<td>${li.fault_name }</td>
									<td class="parts">${li.parts_name }</td>
									<td>${li.opt_user_ }</td>
									<td><vvise:select id="confirmStatus" name="confirmStatus" sqlname="getCodeData" defval="${li.confirm_status }"
										sqlparam="yes_or_no" className="full_select" ifSelect="${ifSelect }"/></td>
									<td class="${isHide }"><div class="choose_icon" title="更换配件"></div></td>
								</tr>
								</c:if>
							</c:forEach>
						</tbody>
					</table>
				</div>
			</div>
		</div>
	</form>
</body>
<script type="text/javascript">
var wh = $(window).height();
var ht = wh - 20 - 161 - 40 - 5;
$('.tab-body').height(ht);

var Index = function(){
	var bindEvent = function(){
		//tab toggle
		$(document).delegate('.tab-header li', 'click', function(){
			if(!$(this).hasClass('.s0')){
				var $index = $(this).index();
				$(this).siblings('.s0').toggleClass('s0').end().toggleClass('s0');
				$('div.tab-body').find('.s0').toggleClass('s0').end().find('.tab-content:eq('+$index+')').toggleClass('s0');
			}
		});
		
		//change parts info
		$(document).delegate('.choose_icon', 'click', function(){
			var pp = parent;
			var tr_ = $(this).parents('tr');
			var logId = tr_.find('input[name="logId"]').val();
			
			pp.openWindow("更换配件",pp.width2,430,"${ctx}/partsConfirm/changeParts?logId="+logId,[{
				text:'确认',
				iconCls:'icon-ok',
				handler:function(){
					chooseParts(tr_);
				}
			},{
				text:'取消',
				iconCls:'icon-no',
				handler:function(){
					pp.closeWindow('winDiv2');
				}
			}],'','winDiv2');
		});
	};
	
	var chooseParts = function(tr){
		var pp = parent;
		var listFrame = pp.winFrame2;
		var all = listFrame.document.all.partsName;
		var partsStr = $(all).map(function(){return $(this).val()}).get().join('，');
		partsStr = partsStr.replace(/，/g, "; ");
		//console.log(partsStr)
		$(tr).find('.parts').text(partsStr);
		pp.closeWindow('winDiv2');
	};
	
	
	//有效性验证
	var requiredValid = function(){
		var pp = parent;
		
		//气瓶
		var qpTR = $('#qp tbody tr');
		for(var i=0, tr; (tr=qpTR[i])!=null; i++){
			var confirmStatus = $(tr).find('select[name="confirmStatus"]').val();
			if(pp.isEmpty(confirmStatus)){
				if(!$('.tab-header li:eq(0)').hasClass('s0')){
					$('.tab-header li:eq(0)').click();
				}
				pp.$.messager.alert('操作提示','请选择第【'+ (i+1) +'】行配件确认状态！',"warning");
				return false;
			}
		}
		
		//气检仪
		var qjyTR = $('#qjy tbody tr');
		for(var i=0, tr; (tr=qjyTR[i])!=null; i++){
			var confirmStatus = $(tr).find('select[name="confirmStatus"]').val();
			if(pp.isEmpty(confirmStatus)){
				if(!$('.tab-header li:eq(1)').hasClass('s0')){
					$('.tab-header li:eq(1)').click();
				}
				pp.$.messager.alert('操作提示','请选择第【'+ (i+1) +'】行配件确认状态！',"warning");
				return false;
			}
		}
		
		//空呼
		var khTR = $('#kh tbody tr');
		for(var i=0, tr; (tr=khTR[i])!=null; i++){
			var confirmStatus = $(tr).find('select[name="confirmStatus"]').val();
			if(pp.isEmpty(confirmStatus)){
				if(!$('.tab-header li:eq(2)').hasClass('s0')){
					$('.tab-header li:eq(2)').click();
				}
				pp.$.messager.alert('操作提示','请选择第【'+ (i+1) +'】行配件确认状态！',"warning");
				return false;
			}
		}
		
		return true;
	};
	return {
		init: function(){
			bindEvent();
		},
		required: function(){
			return requiredValid();
		}
	};
}();

$(function(){
	Index.init();
});
</script>
</html>